﻿using System;
using System.Collections.Generic;
using Microsoft.SmallBasic.Library;

namespace SmallBasicFun
{
	
	public class Wheel<T>
	{
		private List<T> wheel = new List<T>();
		private int index;

		public Wheel(params T[] startingValues)
		{
			foreach (var value in startingValues)
			{
				Add(value);
			}
		}


		public void Add(T color)
		{
			wheel.Add(color);
		}

		
		public T GetNext()
		{
			if (index >= wheel.Count)
			{
				index = 0;
			}
			if (wheel.Count == 0)
			{
				return ReturnIfEmpty();
			}
			var color = wheel[index++];
			
			return color;
		}

		public virtual T ReturnIfEmpty()
		{
			return default(T);
		}

		public T GetRandom()
		{
			if (wheel.Count == 0)
			{
				return ReturnIfEmpty();
			}
			var color = wheel[new Random().Next(wheel.Count)];

			return color;
		}

		
		public void RemoveAll()
		{
			wheel.Clear();
			index = 0;
		}
	}
}